package com.lianzhihui.romeex.adapter;

import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lianzhihui.romeex.MyApplication;
import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.bean.WalletMainBean;
import com.lianzhihui.romeex.utils.NumberUtils;
import com.lianzhihui.romeex.utils.UserUtils;

import java.util.List;

/**
 * Description: 主页适配器
 * Author: RAMON
 * CreateDate: 2020/11/4 8:10 PM
 * UpdateUser:
 * UpdateDate:
 * UpdateRemark:
 * Version:
 */
public class CoinAdapter extends BaseQuickAdapter<WalletMainBean.CoinBean, BaseViewHolder> {

    public CoinAdapter(@Nullable List<WalletMainBean.CoinBean> data) {
        super(R.layout.item_coin_layout, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, WalletMainBean.CoinBean item) {

        Glide.with(mContext).load(item.getLogo()).into((ImageView) helper.getView(R.id.item_icon));

        helper.setText(R.id.item_name, item.getCoinNameAlias());

        String price;
        String moneyStr;
        if (UserUtils.getCurrentyType() == 1) {
            price = NumberUtils.big2(item.getPriceCny());
            moneyStr = "¥";
        } else {
            price = NumberUtils.big2(item.getPrice());
            moneyStr = "$";
        }

        if (item.getRise().contains("-")) {
            //跌
            helper.setTextColor(R.id.item_float, mContext.getResources().getColor(R.color.red));
            price = moneyStr + price + "↓";
        } else {
            helper.setTextColor(R.id.item_float, mContext.getResources().getColor(R.color.green));
            price = moneyStr + price + "↑";
        }
        helper.setText(R.id.item_float, price);

        helper.setText(R.id.item_canuse, NumberUtils.big2(item.getValidBalance()));
        helper.setText(R.id.item_freeze, NumberUtils.big2(item.getLockBalance()));
        helper.setText(R.id.item_count, NumberUtils.big2(item.getTotalBalance()));

        if (item.getCoinName().equals(mContext.getString(R.string.text_rex))) {

            helper.setText(R.id.item_Profit, NumberUtils.big8(item.getProfitBalance()));
            helper.setText(R.id.item_simu, NumberUtils.big8(item.getPlacementBalance()));

        } else if (item.getCoinName().equals(mContext.getString(R.string.text_xusd))) {

            helper.setGone(R.id.item_shouyi_range, false);
            helper.setText(R.id.title_simu, MyApplication.mContext.getResources().getString(R.string.text_node_points));
            helper.setText(R.id.item_simu, NumberUtils.big8(item.getMinerIntegral()));

        } else {
            helper.setGone(R.id.item_shouyi_range, false);
            helper.setGone(R.id.item_simu, false);
            helper.setGone(R.id.title_simu, false);
        }
    }
}
